﻿CREATE FUNCTION [dbo].[fn_ViewExists]
(
	@View sysname
)
RETURNS BIT
AS
BEGIN
	DECLARE @True  BIT; SET @True  = 1
	DECLARE @False BIT; SET @False = 0
	DECLARE @Object sysname; SET @Object = PARSENAME(@View, 1)
	DECLARE @Schema sysname; SET @Schema = ISNULL(PARSENAME(@View, 2), 'dbo')
	
	IF EXISTS (
	       SELECT *
	       FROM   sys.[views] v
	       WHERE  v.[name] = @Object
	       AND schema_name(schema_id) = @Schema
	   )
	    RETURN @True
	
	RETURN @False
END